<?php

namespace App\Http\Controllers\Company;

use App\Models\Common\CollPosition;
use App\Http\Requests;
use App\Models\Company\CompanyBasic;
use App\Models\Personal\BuyResume;
use App\Models\Personal\ResumeSend;
use Illuminate\Support\Facades\File;
use Style,Index,Cache,DB,Site;
use App\Models\Common\CollArea;
use App\Models\Common\CollOption;
use App\Models\Personal\Resume;
use App\Models\Personal\ResumeCertificate;
use App\Models\Personal\ResumeEducationExp;
use App\Models\Personal\ResumeExtra;
use App\Models\Personal\ResumeLanguageSkill;
use App\Models\Personal\ResumeOther;
use App\Models\Personal\ResumeProjectExp;
use App\Models\Personal\ResumeSkill;
use App\Models\Personal\ResumeWorkExp;
use App\Models\Personal\ResumeWorks;
use Auth;

class ResumeDownController extends CommonController
{
    public function resumeDown($resumeId){
       //判断企业是否登录
       if(Auth::guard('company')->check()){
           $user = Auth::guard('company')->user();
           //简历被购买查看过
           $BuyResume = BuyResume::where('company_uid',$user->uid)->where('resume_id',$resumeId)->first();
           if(!empty($BuyResume)){//简历被购买查看过
               return $this->toPrintResume($resumeId);
           }else{
               //在会员期内投递过简历
               $ResumeSend = ResumeSend::select('created_at')->where("resume_id",$resumeId)->where('company_uid',$user->uid)->first();
               if(!empty($ResumeSend)){
                   if($user->viptime > date('Y-m-d H:i:s')){
                       return $this->toPrintResume($resumeId);
                   }
               }
               //无投递过简历&&无购买过=》判断简历数
               if($user->resumeNumber() > 0){
                   if($user->resumeDeduct(1)){
                       $companyBasic = CompanyBasic::select('id')->where('uid',$user->uid)->first();
                       $resume = Resume::select('uid')->where('id',$resumeId)->first();
                       $input['company_uid'] = $user->uid;
                       $input['personal_uid'] = $resume->uid;
                       $input['resume_id'] = $resumeId;
                       $input['com_id'] = !empty($companyBasic) ? $companyBasic->id:'';
                       BuyResume::create($input);
                       //有简历数，下载简历
                       return $this->toPrintResume($resumeId);
                   }
               }
           }
       }
    }

    /**
     * 简历doc下载
     * @param $uid
     * @throws \PhpOffice\PhpWord\Exception\Exception
     */
    public function toPrintResume($id){

        //获得简历信息
        $id = $id;
        //读取基本信息
        $resume = Resume::where('id',$id)->first();//resume_status
        if($resume) {
            //头像
            if (!empty($resume->avatar) && $resume->chkphoto_open == 0) {

                if(!file_exists('upload/personalavatar/'.$resume->avatar)){
                    if ($resume->sex == '1') {
                        $resume->avatar = public_path().'/default/images/mobile/layout/photo01.png';
                    } else if ($resume->sex == '2') {
                        $resume->avatar = public_path().'/default/images/mobile/layout/photo02.png';
                    }
                }else{
                    $resume->avatar = public_path().'/upload/personalavatar/'.$resume->avatar;
                }

            } else if ($resume->sex == '1') {
                $resume->avatar = public_path().'/default/images/mobile/layout/photo01.png';
            } else if ($resume->sex == '2') {
                $resume->avatar = public_path().'/default/images/mobile/layout/photo02.png';
            }

            //学历
            $resume->education = CollOption::getOptionName($resume->education, 'education');
            //工作时长
            $resume->work_year = CollOption::getOptionName($resume->work_year, 'work_year');
            //工作状态
            $resume->job_status = CollOption::getOptionName($resume->job_status, 'job_status');
            //性别
            $resume->sex = ($resume->sex == '1') ? '男' : '女';
            //婚姻
            $resume->marital = empty($resume->marital) ? '保密' : CollOption::getOptionName($resume->marital, 'marital');
            //户藉
            $resume->census = empty($resume->census) ? '未填写' : CollArea::getAreaName($resume->census);
            //身高
            $resume->height = empty($resume->height) ? '未填写' : $resume->height . 'CM';
            //工作地区
            if (empty($resume->jobarea1)) {
                $resume->jobarea1 = '';
            } else {
                $resume->jobarea1 = CollArea::getAreaName($resume->jobarea1);
            }
            if (empty($resume->jobarea2)) {
                $resume->jobarea2 = '';
            } else {
                $resume->jobarea2 = CollArea::getAreaName($resume->jobarea2);
            }
            if (empty($resume->jobarea3)) {
                $resume->jobarea3 = '';
            } else {
                $resume->jobarea3 = CollArea::getAreaName($resume->jobarea3);
            }
            if (empty($resume->jobarea4)) {
                $resume->jobarea4 = '';
            } else {
                $resume->jobarea4 = CollArea::getAreaName($resume->jobarea4);
            }
            if (empty($resume->jobarea5)) {
                $resume->jobarea5 = '';
            } else {
                $resume->jobarea5 = CollArea::getAreaName($resume->jobarea5);
            }
            $resume->jobarea = $resume->jobarea1 . ' ' . $resume->jobarea2 . ' ' . $resume->jobarea3 . ' ' . $resume->jobarea4 . ' ' . $resume->jobarea5;
            //工作岗位
            CollPosition::getPosName($resume->jobsort1);
            if (empty($resume->jobsort1)) {
                $resume->jobsort1 = '';
            } else {
                $resume->jobsort1 = CollPosition::getPosName($resume->jobsort1);
            }
            if (empty($resume->jobsort2)) {
                $resume->jobsort2 = '';
            } else {
                $resume->jobsort2 = CollPosition::getPosName($resume->jobsort2);
            }
            if (empty($resume->jobsort3)) {
                $resume->jobsort3 = '';
            } else {
                $resume->jobsort3 = CollPosition::getPosName($resume->jobsort3);
            }
            if (empty($resume->jobsort4)) {
                $resume->jobsort4 = '';
            } else {
                $resume->jobsort4 = CollPosition::getPosName($resume->jobsort4);
            }
            if (empty($resume->jobsort5)) {
                $resume->jobsort5 = '';
            } else {
                $resume->jobsort5 = CollPosition::getPosName($resume->jobsort5);
            }
            $resume->jobsort = $resume->jobsort1 . ' ' . $resume->jobsort2 . ' ' . $resume->jobsort3 . ' ' . $resume->jobsort4 . ' ' . $resume->jobsort5;
            //工资
            $resume->expectedsalary = empty($resume->expectedsalary) ? '面议' : CollOption::getOptionName($resume->expectedsalary, 'expectedsalary') . '元/月';

            //获取邮箱
            if (!empty($resume->email)) {
                list($before, $after) = explode('@', $resume->email);
                $sNum = str_repeat('*', abs(strlen($before) - 4));
                $before = str_replace(substr($before, 2, -2), $sNum, $before);
                $resume->stremail = $before . '@' . $after;
            } else {
                $resume->stremail = '';
            }
            //获取手机
            if (!empty($resume->mobile)) {
                $resume->strmobile = preg_replace('/(\d{3})(\d{4})(\d{4})/i', '$1****$3', $resume->mobile);
            } else {
                $resume->strmobile = '';
            }

            //工作经验
            $ResumeWorkExp = ResumeWorkExp::select('starttime', 'endtime', 'company', 'industry','post','content')->
            where('resume_id', $resume->id)->where('uid', $resume->uid)->get();
            //教育经历
            $ResumeEducationExp = ResumeEducationExp::select('starttime', 'endtime', 'school', 'speciality')->
            where('resume_id', $resume->id)->where('edu_type', 1)->where('uid', $resume->uid)->get();
            //培训经历
            $trainExp = ResumeEducationExp::select('starttime', 'endtime', 'school', 'speciality')->
            where('resume_id', $resume->id)->where('edu_type', 2)->where('uid', $resume->uid)->get();
            //项目经验
            $ResumeProjectExp = ResumeProjectExp::select('project_name', 'starttime', 'endtime', 'post')
                ->where('resume_id', $resume->id)->where('uid', $resume->uid)->get();
            //语言能力
            $ResumeLanguageSkill = ResumeLanguageSkill::select('language', 'degree')
                ->where('resume_id', $resume->id)->where('uid', $resume->uid)->get();
            //技能专长
            $ResumeSkill = ResumeSkill::select('skillname', 'degree')->where('resume_id', $resume->id)
                ->where('uid', $resume->uid)->get();
            //证书
            $ResumeCertificate = ResumeCertificate::select('certificate_name', 'gettime')
                ->where('resume_id', $resume->id)->where('uid', $resume->uid)->get();
            //其它信息
            $ResumeOther = ResumeOther::select('title', 'content')->where('resume_id', $resume->id)
                ->where('uid', $resume->uid)->get();
            //我的作品
            $works = ResumeWorks::select('id', 'works_name')
                ->whereHas('worksBelongImg', function ($query) {
                    $query->orderBy('id', 'desc');
                })
                ->with(["worksBelongImg" => function ($query) {
                    $query->select('id', 'works_id', 'imgurl', 'originalimg')
                        ->orderBy("resume_works_img.id", 'desc');
                }])
                ->where('uid', $resume->uid)->get();
            $worksType = ['gif', 'jpg', 'jpeg', 'bmp', 'png'];
        }

        //初始化phpword
        $PHPWord = new \PhpOffice\PhpWord\PhpWord();

        //字体与大小
        $PHPWord->setDefaultFontName('simsun');
        $PHPWord->setDefaultFontSize(12);

        //word 页面宽高
        $sectionStyle = array('orientation' => null,
            'marginLeft' => 700,		//设置页面宽高
            'marginRight' => 700,
            'marginTop' => 900
        );
        $section = $PHPWord->addSection($sectionStyle);

        //页面边距
        $styleTable = array(						//设置表格样式
            'borderColor'=>'006699',
            'borderSize'=>6,
            'cellMarginTop'=>20,
            'cellMarginLeft'=>50,
            'cellMarginRight'=>50,
            'cellMarginBottom'=>20
        );

        //表格默认样式
        $styleFirstRow = array('bgColor'=>'ffffff');	//设置表格第一行样式
        $PHPWord->addTableStyle('myTable',$styleTable,$styleFirstRow);
        $PHPWord->addTableStyle('myTable2',$styleTable,$styleFirstRow);
        $PHPWord->addTableStyle('myTable3',$styleTable,$styleFirstRow);
        $PHPWord->addTableStyle('myTable4',$styleTable,$styleFirstRow);
        $PHPWord->addTableStyle('myTable5',$styleTable,$styleFirstRow);
        $PHPWord->addTableStyle('myTable6',$styleTable,$styleFirstRow);
        $PHPWord->addTableStyle('myTable7',$styleTable,$styleFirstRow);
        //页眉
        $header = $section->createHeader();
        $header->addImage(public_path().'/default/images/logo/index.png',array('width'=>80,'height'=>23,'align'=>'left'));

        //简历标题
        $perName = $resume->name;
        $text =$perName.'个人简历';
        $fontStyle =array('size'=>20,'bold'=>true);						//文本样式
        $paragraphStyle = array('align'=>'center','spaceAfter'=>140);	//段落样式居中和段后间距
        $section->addText( $text, $fontStyle,$paragraphStyle);			//添加文本内容和样式


        //word表格
        $cellStyle = array('valign'=>'center');							//单元格行高居中
        $fontstyle1 = array('size'=>13,'bold'=>true);					//单元格样式.
        $paragraphStyle1 = array('align'=>'center');					//单元格段落样式
        $pHeight = 650;													//单元格高度
        $pWidth = 1500;													//单元格宽度
        $pWidth2 = 1800;												//单元格宽度

        $verticalMerger = array('rowMerge' => 'restart', 'valign' => "center") ;//纵向合并

        $table = $section->addTable('myTable');
        //基本资料 样式------------------------------------------------------------------------------------------------
        $table->addRow($pHeight);
        $table->addCell($pWidth,$cellStyle)->addText('姓名',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText($resume->name,array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText('性别',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText($resume->sex,array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText('出生日期',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText($resume->birthday,array(),$paragraphStyle1);
        $imageStyle1 = array('width'=>106, 'height'=>125,'align'=>'center');

        $table->addCell($pWidth2,$verticalMerger)->addImage($resume->avatar,$imageStyle1);//$resume->avatar,$imageStyle1

        $table->addRow($pHeight);
        $table->addCell($pWidth,$cellStyle)->addText('身高',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText($resume->height,array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText('工作经验',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText($resume->work_year,array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText('求职状态',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText($resume->job_status,array(),$paragraphStyle1);
        $table->addCell($pWidth2, array('rowMerge' => 'continue'));

        $table->addRow($pHeight);
        $table->addCell($pWidth,$cellStyle)->addText('学历',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText($resume->education,array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText('婚姻状况',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText($resume->marital,array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText('',array(),$paragraphStyle1);
        $table->addCell($pWidth,$cellStyle)->addText('',array(),$paragraphStyle1);
        $table->addCell($pWidth2, array('rowMerge' => 'continue'));
        $section->addTextBreak();
        //第二个表格 联系方式
        $fontStyle2 =array('size'=>16,'bold'=>true);								//文本样式
        $section->addText( '联系方式',$fontStyle2,array('align'=>'left'));			//添加文本内容和样式
        $pWidth3 = 3900;															//单元格宽度

        $table2 = $section->addTable('myTable2');
        $table2->addRow($pHeight);
        $table2->addCell($pWidth,$cellStyle)->addText('户籍',array(),$paragraphStyle1);
        $table2->addCell($pWidth3,$cellStyle)->addText($resume->census,array(),$paragraphStyle1);
        $table2->addCell($pWidth,$cellStyle)->addText('居住地',array(),$paragraphStyle1);
        $table2->addCell($pWidth3,$cellStyle)->addText($resume->homeaddress,array(),$paragraphStyle1);

        $table2->addRow($pHeight);
        $table2->addCell($pWidth,$cellStyle)->addText('聊天号码',array(),$paragraphStyle1);
        $table2->addCell($pWidth3,$cellStyle)->addText($resume->qq,array(),$paragraphStyle1);
        $table2->addCell($pWidth,$cellStyle)->addText('手机号码',array(),$paragraphStyle1);
        $table2->addCell($pWidth3,$cellStyle)->addText($resume->mobile,array(),$paragraphStyle1);

        $table2->addRow($pHeight);
        $table2->addCell($pWidth,$cellStyle)->addText('电子邮件',array(),$paragraphStyle1);
        $table2->addCell($pWidth3,$cellStyle)->addText($resume->email,array(),$paragraphStyle1);
        $table2->addCell($pWidth,$cellStyle)->addText('地址',array(),$paragraphStyle1);
        $table2->addCell($pWidth3,$cellStyle)->addText($resume->address,array(),$paragraphStyle1);

        $section->addTextBreak();

        //第三个表格 求职意向
        $section->addText( '求职意向',$fontStyle2,array('align'=>'left'));			//添加文本内容和样式
        $table3 = $section->addTable('myTable3');
        $pWidth4 = 9300;															//单元格宽度

        $table3->addRow($pHeight);
        $table3->addCell($pWidth,$cellStyle)->addText('希望岗位',array());
        $table3->addCell($pWidth4,$cellStyle)->addText($resume->intentionjobs,array());

        $table3->addRow($pHeight);
        $table3->addCell($pWidth,$cellStyle)->addText('寻求职位',array());
        $table3->addCell($pWidth4,$cellStyle)->addText($resume->jobsort,array());

        $table3->addRow($pHeight);
        $table3->addCell($pWidth,$cellStyle)->addText('工作地点',array());
        $table3->addCell($pWidth4,$cellStyle)->addText($resume->jobarea,array());

        $table3->addRow($pHeight);
        $table3->addCell($pWidth,$cellStyle)->addText('期望工资',array());
        $table3->addCell($pWidth4,$cellStyle)->addText($resume->expectedsalary,array());

        $section->addTextBreak();

        //工作经历
        if(count($ResumeWorkExp) > 0){
            $str = "工作经历";
            $section->addText($str,$fontStyle2,array('align'=>'left'));//添加文本内容和样式
            $table4 = $section->addTable('myTable4');
            $pWidth41 = 10800;	//单元格宽度
            $cellStyle41 = array('valign'=>'center','bgColor'=>'eeeeee');	//单元格行高居中

            $table4->addRow($pHeight);
            $table4->addCell($pWidth41,$cellStyle41)->addText('工作经历',array());
            foreach ($ResumeWorkExp as $v) {
                $v->starttime = substr($v->starttime, 0, 7);
                $v->endtime = ($v->endtime == '0000-00-00') ? '至今' : substr($v->endtime, 0, 7);
                $line1 = "在职时间：".$v->starttime."~~".$v->endtime.":".$v->company;
                $table4->addRow($pHeight);
                $fontStyle = array('color'=>'21a74f',  'bold'=>true);
                $table4->addCell($pWidth41,$cellStyle)->addText($line1,$fontStyle);

                $v->industry = CollOption::getOptionName($v->industry, 'industry');
                $line2 = "所属行业：".$v->industry;
                $table4->addRow($pHeight);
                $table4->addCell($pWidth41,$cellStyle)->addText($line2,array());

                $v->industry = CollOption::getOptionName($v->industry, 'industry');
                $line3 = "职位名称：".$v->post;
                $table4->addRow($pHeight);
                $table4->addCell($pWidth41,$cellStyle)->addText($line3,array());

                $line4 = "职位描述：".$v->content;
                $table4->addRow($pHeight);
                $table4->addCell($pWidth41,$cellStyle)->addText($line4,array());
            }
        }

        //教育经历
        if(count($ResumeEducationExp) > 0){
            $str = "教育经历";
            $section->addText($str,$fontStyle2,array('align'=>'left'));//添加文本内容和样式
            $table4 = $section->addTable('myTable4');
            $pWidth41 = 10800;	//单元格宽度
            $cellStyle41 = array('valign'=>'center','bgColor'=>'eeeeee');	//单元格行高居中

            $table4->addRow($pHeight);
            $table4->addCell($pWidth41,$cellStyle41)->addText('教育经历',array());

            foreach ($ResumeEducationExp as $v) {
                $line1 = "学校名称：".$v->school;
                $table4->addRow($pHeight);
                $fontStyle = array('color'=>'21a74f',  'bold'=>true);
                $table4->addCell($pWidth41,$cellStyle)->addText($line1,$fontStyle);

                $v->starttime = substr($v->starttime, 0, 7);
                $v->endtime = ($v->endtime == '0000-00-00') ? '至今' : substr($v->endtime, 0, 7);
                $line2 = "在校时间：".$v->starttime."~~".$v->endtime.":".$v->company;
                $table4->addRow($pHeight);
                $table4->addCell($pWidth41,$cellStyle)->addText($line2,'');

                $line3 = "所学专业：".$v->speciality;
                $table4->addRow($pHeight);
                $table4->addCell($pWidth41,$cellStyle)->addText($line3,'');

                $line4 = "学历：：".$v->education;
                $table4->addRow($pHeight);
                $table4->addCell($pWidth41,$cellStyle)->addText($line4,'');
            }
        }

        //自我评价
        if(!empty($resume->introduction)){
            $str = "自我评价";
            $section->addText($str,$fontStyle2,array('align'=>'left'));//添加文本内容和样式
            $table4 = $section->addTable('myTable4');
            $pWidth41 = 10800;	//单元格宽度
            $cellStyle41 = array('valign'=>'center','bgColor'=>'eeeeee');	//单元格行高居中

            $table4->addRow($pHeight);
            $table4->addCell($pWidth41,$cellStyle41)->addText('自我评价',array());
            $table4->addRow($pHeight);
            $table4->addCell($pWidth41,$cellStyle)->addText($this->wordBr($resume->introduction),array());
            $section->addTextBreak();
        }

        //第五个表格 技术&语言&证书
        if(count($ResumeLanguageSkill) > 0 || count($ResumeSkill) > 0 || count($ResumeCertificate) > 0){
            $section->addText('技能专长',$fontStyle2,array('align'=>'left'));			//添加文本内容和样式
            $table5 = $section->addTable('myTable5');
        }

        //语言能力
        if(count($ResumeLanguageSkill) > 0){
            $table5->addRow($pHeight);
            $table5->addCell($pWidth41,$cellStyle41)->addText('语言能力',array());
            foreach ($ResumeLanguageSkill as $v) {
                $v->language = CollOption::getOptionName($v->language, 'language');
                $v->degree = CollOption::getOptionName($v->degree, 'degree');
                $table5->addRow($pHeight);
                $line = $v->language.'：'.$v->degree;
                $table5->addCell($pWidth41,$cellStyle)->addText($line,'');
            }
            $section->addTextBreak();
        }

        //技能
        if(count($ResumeSkill) > 0){
            $table5->addRow($pHeight);
            $table5->addCell($pWidth41,$cellStyle41)->addText('技能',array());
            foreach ($ResumeSkill as $v) {
                $v->degree = CollOption::getOptionName($v->degree, 'degree');
                $table5->addRow($pHeight);
                $line = $v->skillname.'：'.$v->degree;
                $table5->addCell($pWidth41,$cellStyle)->addText($line,'');
            }
            $section->addTextBreak();
        }

        //证书
        if(count($ResumeCertificate) > 0){
            $table5->addRow($pHeight);
            $table5->addCell($pWidth41,$cellStyle41)->addText('证书',array());
            foreach ($ResumeCertificate as $v) {
                $v->gettime = substr($v->gettime, 0, 4);
                $table5->addRow($pHeight);
                $line = $v->certificate_name.'：'.$v->gettime;
                $table5->addCell($pWidth41,$cellStyle)->addText($line,'');
            }
            $section->addTextBreak();
        }

        //其他信息
        if(count($ResumeOther) > 0){
            $section->addText('其它信息',$fontStyle2,array('align'=>'left'));			//添加文本内容和样式
            $table6 = $section->addTable('myTable6');
            foreach ($ResumeOther as $v) {
                $table6->addRow($pHeight);
                $line = $v->title.'：'.$v->content;
                $table6->addCell($pWidth41,$cellStyle)->addText($line,'');
            }
            $section->addTextBreak();
        }

        //作品
        if(count($works) > 0){
            $section->addText('作品',$fontStyle2,array('align'=>'left'));
            $table7 = $section->addTable('myTable7');
            foreach ($works as $k=>$v) {
                $suffix = substr(strrchr($v->worksBelongImg->imgurl, '.'), 1);
                if (in_array($suffix, $worksType)) {
                    $imgurl = 'upload/personalworks/' . $v->worksBelongImg->imgurl;
                } else {
                    switch ($suffix) {
                        case 'doc' :
                            $imgurl = 'default/images/personal/doc.jpg';
                            break;
                        case 'docx' :
                            $imgurl = 'default/images/personal/doc.jpg';
                            break;
                        case 'ppt' :
                            $imgurl = 'default/images/personal/ppt.jpg';
                            break;
                        case 'pptx' :
                            $imgurl = 'default/images/personal/ppt.jpg';
                            break;
                        case 'xls' :
                            $imgurl = 'default/images/personal/xls.jpg';
                            break;
                        case 'xlsx' :
                            $imgurl = 'default/images/personal/xls.jpg';
                            break;
                        case 'pdf' :
                            $imgurl = 'default/images/personal/pdf.jpg';
                            break;
                        case 'txt' :
                            $imgurl = 'default/images/personal/txt.jpg';
                            break;
                        default :
                            $imgurl = '未知';
                            break;
                    }
                }
                $v->worksBelongImg->imgurl = public_path().'/'.$imgurl;
                $table7->addRow($pHeight);
                $line = '作品'.($k+1).'：';

                $table7->addCell(1800,$cellStyle)->addText($line);
                if(file_exists($v->worksBelongImg->imgurl)){
                    $table7->addCell(9000,$cellStyle)->addImage($v->worksBelongImg->imgurl ,array('width'=>80,'height'=>80,'align'=>'left'));
                }
            }
        }
        //页脚
        $footer = $section->createFooter();
        $footerCss = array('align'=>'center');			;
        $footer->addText(Site::get('webname') . ' 热线电话：' . Site::get('tel'), $footerCss, $footerCss);

        $fileName = iconv('utf-8','gbk',$resume->name).date("YmdHis");
        header("Content-type: application/vnd.ms-word");
        header("content-Type: application/vnd.ms-word; charset=Utf-8");
        header("Content-Disposition:attachment;filename=".$fileName.".docx");
        header('Cache-Control: max-age=0');
        $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007');//Word2007    //HTML
        //$objWriter->save($fileName.'.doc');
        @$objWriter->save('php://output');
    }

    /**
     * \r\n换成 w br
     * @param $str
     * @return mixed
     */
    protected function wordBr($str){
        return str_replace("\r\n",'<w:br />',$str);
    }
}
